package 算法.力扣;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: 谢君臣
 * @create: 2020-12-12 18:30
 * @founction: XXXX
 */
public class Lc1553 {
    public static void main(String[] args) {
        Map<Integer, Integer> map = new HashMap<>();
        int rest = 820592;
        map.put(1, 1);
        map.put(2, 2);
        map.put(3, 2);
        minDay(rest, map);
        System.out.println(map.get(rest));
    }

    public static int minDay(int rest, Map<Integer, Integer> map) {
        if (map.containsKey(rest))
            return map.get(rest);
        else {
            int temp1 = minDay(rest - 1, map);
            int temp2 = Integer.MAX_VALUE;
            int temp3 = Integer.MAX_VALUE;
            if (rest % 2 == 0)
                temp2 = minDay(rest / 2, map);
            if (rest % 3 == 0)
                temp3 = minDay(rest / 3, map);
            map.put( rest,Math.min(Math.min(temp1,temp2),temp3)+1);
            return map.get(rest);
        }
    }
}
